<template>
  <view class="tabbar" @touchmove.stop.prevent>
    <view class="item" v-for="(item, index) in list" :key="item.text" @click="changeTab(index, item)">
      <image :src="index === tabIndex ? item.selectedIconPath : item.iconPath"></image>
      <text :class="{ active: index === tabIndex }">{{item.text}}</text>
    </view>
  </view>
</template>

<script>
  export default {
    props: {
      list: {
        type: Array,
        default: () => {
          return []
        }
      }
    },
    name: 'TabBar',
    data() {
      return {
        tabIndex: 0
      };
    },
    methods: {
      changeTab(index, item) {
        if(index !== this.tabIndex) {
          this.tabIndex = index
          this.$emit('change', { index, item })
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  @import './index.scss';
</style>
